{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 百度新闻摘要"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests_html import HTMLSession"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.0f175e98ce0175cf7cce84db805b1e82.315360000.1909787679.282335-19897464', 'expires_in': 2592000, 'session_key': '9mzdCS6arh0Dj7aQrtnCCZA51qPXAphbE3GFNWaMO5S9HB6sIj0ZkaywFvkqVMtDFTs+Wbx8sYo4QOP53gnzvn4HSsgWXw==', 'access_token': '24.283ad1cbf0247c995a623a9ff78f5d0f.2592000.1597019679.282335-19897464', 'scope': 'public nlp_simnet nlp_wordemb nlp_comtag nlp_dnnlm_cn brain_nlp_lexer brain_all_scope brain_nlp_comment_tag brain_nlp_dnnlm_cn brain_nlp_word_emb_vec brain_nlp_word_emb_sim brain_nlp_sentiment_classify brain_nlp_simnet brain_nlp_depparser brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_comment_tag_legacy brain_nlp_lexer_custom brain_nlp_keyword brain_nlp_topic brain_nlp_ecnet brain_nlp_emotion brain_nlp_comment_tag_custom brain_nlp_news_summary brain_nlp_sentiment_classify_custom brain_nlp_address wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理', 'session_secret': 'b772a98760cdd07cce30d05a0cf6b3ab'}\n"
     ]
    }
   ],
   "source": [
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=a6NboH9ebGu2dtfoOIBH6ReX&client_secret=y60MKflWI8dWfkwDSWCaGhBtPcDmEhYk'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 3814085150139743979, 'summary': '7月9日20时11分，我国在西昌卫星发射中心用长征三号乙运载火箭，成功将亚太6D卫星送入预定轨道，发射获得圆满成功。亚太6D卫星的发射，实现了该平台在国际商业航天舞台上的首次亮相。火箭瘦身亚太6D卫星的重量为5550公斤，对于火箭运力而言，它超重了。执行此次发射任务的长征三号乙运载火箭，地球同步转移轨道运载能力为5500公斤，比卫星重量少50公斤。'}\n"
     ]
    }
   ],
   "source": [
    "url='https://aip.baidubce.com/rpc/2.0/nlp/v1/news_summary?access_token=24.283ad1cbf0247c995a623a9ff78f5d0f.2592000.1597019679.282335-19897464'\n",
    "headers={'Content-Type':'application/json'}\n",
    "data = {\n",
    "    #'access_token': '24.283ad1cbf0247c995a623a9ff78f5d0f.2592000.1597019679.282335-19897464'\n",
    "    \"title\":title,\n",
    "    \"content\": content,\n",
    "    \"max_summary_len\":200\n",
    "}\n",
    "response = requests.post(url,headers=headers,json=data)\n",
    "print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests_html import HTMLSession\n",
    "def summary(title,content):\n",
    "    url='https://aip.baidubce.com/rpc/2.0/nlp/v1/news_summary?access_token=24.283ad1cbf0247c995a623a9ff78f5d0f.2592000.1597019679.282335-19897464'\n",
    "    headers={'Content-Type':'application/json'}\n",
    "    data = {\n",
    "      #'access_token': '24.283ad1cbf0247c995a623a9ff78f5d0f.2592000.1597019679.282335-19897464'\n",
    "      \"title\":title,\n",
    "      \"content\": content,\n",
    "      \"max_summary_len\":140\n",
    "               }\n",
    "    response = requests.post(url,headers=headers,json=data)\n",
    "    return(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'log_id': 3692382468885504530,\n",
       " 'summary': '2016年7月，我国首个Ku频段全球高通量宽带卫星系统启动建设，亚太6D卫星正是该系统的首星。亚太6D卫星共有8个地面关口站，可以支持近100兆的应用速率。据五院亚太6D卫星总指挥、总设计师魏强介绍，该卫星在载荷重量、通信容量、设计复杂程度等方面，均刷新了国内同类通信卫星的纪录。'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summary(title='刷新国内同类通信卫星多项纪录',content='在飞机、船舶、高铁等交通工具上，以及沙漠、荒山等地面基站信号覆盖不到的地方，如何满足用户对宽带互联网的应用需求？2016年7月，我国首个Ku频段全球高通量宽带卫星系统启动建设，亚太6D卫星正是该系统的首星。该卫星主要面向亚太区域用户，可提供全地域、全天候的卫星宽带通信服务，以满足海事通信、航空机载通信、陆地车载通信以及固定卫星宽带互联网接入等多种应用需求。五院西安分院亚太6D卫星副总师周颖介绍说，亚太6D卫星的通信容量达到50Gbps，相比2017年发射的我国首个高通量卫星——中星16号卫星，高出了1.5倍。高通量卫星如同架设在太空中的空间信号中转站，通过无线电信号转发，使地面用户与地面关口站的互联网连接。亚太6D卫星共有8个地面关口站，可以支持近100兆的应用速率。五院西安分院为卫星后续应用提供了天地一体化设计，可根据用户不同需求灵活分配频率资源，实现关口站之间的灵活切换。与传统广播电视卫星的广域波束天线覆盖方式不同，亚太6D卫星使用的是多波束天线，共有90个用户波束，形成对地面的“蜂窝式”覆盖。单波束容量可达1Gbps以上，可以为用户提供高质量的话音、数据通信服务。据五院亚太6D卫星总指挥、总设计师魏强介绍，该卫星在载荷重量、通信容量、设计复杂程度等方面，均刷新了国内同类通信卫星的纪录。项目团队先后攻克了Ku频段超宽带多端口功率放大器（MPA）、关口站灵活切换等诸多关键技术，使得卫星技术指标与能力达到国际先进水平。')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 腾讯AI自动摘要"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 腾讯AI返回结果"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![腾讯AI代码](./images/apirequest.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 腾讯AI代码"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![腾讯AI代码](./images/apireponse.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
